<!DOCTYPE html>
<html lang="zh-cn"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head th:replace="common::head"></head>
<body>
<div th:replace="common::top"></div>
<br/>
<h2>发货</h2>
<br/>

<table>
    <tr>
        <td><b>编码:</b></td>
        <td th:text="${order.code}"></td>
        <td colspan="2"></td>
        <td><b>订单总量:</b></td>
        <td th:text="${order.orderNum}"></td>
    </tr>
    <tr>
        <td><b>状态:</b></td>
        <td th:text="${order.status}==1?'正常':'撤销'"></td>
        <td><b>已上产线:</b></td>
        <td th:text="${order.confirm}?'是':'否'"></td>
        <td><b>生产总量:</b></td>
        <td th:text="${order.produceNum}"></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td><b>销售:</b></td>
        <td th:text="${order.createUser}"></td>
        <td><b>发送总量:</b></td>
        <td th:text="${order.sendNum}"></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td><b>创建时间:</b></td>
        <td th:text="${#dates.format(order.createTime,'yyyy-MM-dd')}"></td>
        <td><b>退货总量:</b></td>
        <td th:text="${order.refundNum}"></td>
    </tr>
</table>
<br/>
<form th:action="@{send}" method="post">
    <input type="number" name="orderId" th:value="${order.id}" hidden="hidden">
    <table>
        <thead>
        <tr>
            <th>产品</th>
            <th>数量</th>
            <th>产量</th>
            <th>发货</th>
            <th>备注</th>
            <th>发货数量</th>
        </tr>
        </thead>
        <tbody id="batch">
        <tr th:each="item : ${batchList}">

            <td th:text="${item.productName}"></td>
            <td th:text="${item.orderNum}"></td>
            <td>
                <span th:text="${item.produceNum}"></span>
                <span>/</span>
                <span th:text="${item.produceGap}" th:style="${item.produceGap}==0 ? 'color:green':'color:red' "></span>
            </td>
            <td>
                <span th:text="${item.sendNum}"></span>
                <span>/</span>
                <span th:text="${item.sendGap}" th:style="${item.sendGap}==0 ? 'color:green':'color:red' "></span>
            </td>
            <td th:text="${item.remark}"></td>
            <td>
                <input type="number" th:value="${item.id}" hidden="hidden">
                <input type="number" style="width:70px;" min="1" >
            </td>
        </tr>
        </tbody>
    </table>
    <input type="submit" value="发货" style="width: 220px;">
</form>

<p>
    <a href="javascript:history.back(-1);">上一页</a>
    <a href="../index.html" th:href="@{/index.html}">首页</a>
</p>

<script>
    $("form").submit(function(e){
        e.preventDefault();

        var orderId = $('input[name=orderId]').val();

        var arr = [];
        $("#batch tr").each(function(){
            var obj = {};
            obj.batchId = $(this).find("td:eq(5) input:eq(0)").val();
            obj.number = $(this).find("td:eq(5) input:eq(1)").val();
            arr.push(obj);
        });

        $.ajax({
            type: $(e.target).attr("method"),
            url: $(e.target).attr("action"),
            data: $(e.target).serialize() + '&batchJson=' + JSON.stringify(arr),
            success: function(response){
                alert("提交成功");
                window.location.href="detail.html?orderId="+orderId;
            },
            error: function(response){
                alert("提交失败");
            }
        });
    });
</script>
</body>
</html>